package com.lanqiao.companymanage.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.lanqiao.companymanage.entity.User;
import com.lanqiao.companymanage.service.ChangePasswordService;
import com.lanqiao.companymanage.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author WangJunJie
 * 修改密码
 * 这个是User的修改密码
 */
@RestController
@RequestMapping("/ChangePassWord")
@Api(tags = "修改密码")
public class ChangePassWordController {


    @Autowired
    ChangePasswordService changePasswordService;


    @PostMapping("/UserChange")
    @ApiOperation(value = "根据id修改")
    public Result changePassword(@Param("username") String username,@Param("userPassword") String newPassword) {
        UpdateWrapper<User> userUpdateWrapper = new UpdateWrapper<>();
        boolean update = changePasswordService.update(userUpdateWrapper.set("password", newPassword).eq("username", username));
        if (update){
            return Result.success("修改成功");
        }

        return Result.err("修改失败");


    }




}
